{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 矩阵乘法",
   "id": "ab8b31c8cce7b41c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-04T06:21:50.495186Z",
     "start_time": "2025-11-04T06:21:50.491704Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "\n",
    "#定义一个矩阵 3*2\n",
    "A = np.array([\n",
    "    [0,1],\n",
    "    [2,0],\n",
    "    [6,1],\n",
    "    [6,1]\n",
    "])\n",
    "\n",
    "#定义二个矩阵 2*4\n",
    "B =  np.array([\n",
    "    [0,1,4,5],\n",
    "    [2,0,6,7]\n",
    "])\n",
    "\n",
    "result = np.dot(A,B)\n",
    "print(result)\n",
    "\n",
    "result3 = np.dot(B,A)\n",
    "print(result3)\n",
    "\n",
    "C = np.eye(2)\n",
    "result2 = np.dot(A,C)\n",
    "print(result2)\n",
    "\n"
   ],
   "id": "8c2e8d4620cc5eb6",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2  0  6  7]\n",
      " [ 0  2  8 10]\n",
      " [ 2  6 30 37]\n",
      " [ 2  6 30 37]]\n",
      "[[56  9]\n",
      " [78 15]]\n",
      "[[0. 1.]\n",
      " [2. 0.]\n",
      " [6. 1.]\n",
      " [6. 1.]]\n"
     ]
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 神经网络中的初始化",
   "id": "2c9d708fbf5bbf87"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-04T05:58:21.415383Z",
     "start_time": "2025-11-04T05:58:21.411372Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 在神经网络中，单位矩阵可用于权重初始化\n",
    "class SimpleLayer:\n",
    "    def __init__(self, size):\n",
    "        # 使用单位矩阵初始化权重\n",
    "        self.weight = np.eye(size)\n",
    "        self.bias = np.zeros(size)\n",
    "\n",
    "    def forward(self, x):\n",
    "        return np.dot(x, self.weight) + self.bias\n",
    "\n",
    "# 测试\n",
    "layer = SimpleLayer(3)\n",
    "input_data = np.array([1,2,3])\n",
    "output = layer.forward(input_data)\n",
    "\n",
    "print(f\"output: {input_data}\")\n",
    "print(f\"权重矩阵(单位矩阵)\")\n",
    "print(layer.weight)\n",
    "print(f\"反向传播结果输出\")\n",
    "print(output)"
   ],
   "id": "e6f8c38a760ee420",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "output: [1 2 3]\n",
      "权重矩阵(单位矩阵)\n",
      "[[1. 0. 0.]\n",
      " [0. 1. 0.]\n",
      " [0. 0. 1.]]\n",
      "反向传播结果输出\n",
      "[1. 2. 3.]\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "3c53bd94e5dabb97"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "160204dc1448f803"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "f5bdc4d24a677aff"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "e2d04254ec7fb0b6"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "ad6a7d7b1d4b05b4"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "3ebda7b6985123eb"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
